package com.gitee.l0km.codegen.decorator;

import java.util.List;
import java.util.Map;

import org.apache.commons.cli.Options;

import com.gitee.l0km.codegen.base.AbstractSchema;
import com.gitee.l0km.codegen.base.generator.Generator;
import com.gitee.l0km.codegen.base.generator.GeneratorConfiguration;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

public class SpringDecoratorGenerator extends Generator {
	private final SpringDecoratorOptions options = SpringDecoratorOptions.getInstance();
	private final SpringDecoratorConfiguration config = new SpringDecoratorConfiguration();
	public SpringDecoratorGenerator() {
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	protected Map<String, List<? extends AbstractSchema>> generateTask() {
		Class<?> implClass = config.getImplClass();
		SpringDecorator newSourceInfo = new SpringDecorator(implClass)
				.setExcludeAnnotations(config.getExcludeAnnotations())
				.setPortPrefix(config.getPortPrefix());
		if (!newSourceInfo.compile()){
			System.exit(1);
		}
		return ImmutableMap.<String, List<? extends AbstractSchema>>of(".",ImmutableList.of(newSourceInfo));
	}

	@Override
	protected GeneratorConfiguration getGeneratorConfiguration() {
		return config;
	}
	@Override
	protected Options getOptions() {
		return options.getOptions();
	}
	public static void main(String[] args) {
		new SpringDecoratorGenerator().parseCommandLine(args).initEngine().multiGenerate();
	}
}
